﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace JXT.PrimaryKey.Batman.Validation
{
    public class ValidationResult : IEquatable<ValidationResult>
    {
        public ValidationErrorCollection Errors { get; private set; }

        public bool IsValid
        {
            get
            {
                return Errors.Count == 0;
            }
        }

        public ValidationResult()
        {
            Errors = new ValidationErrorCollection();
        }

        public ValidationResult(IEnumerable<ValidationError> errors)
            : this()
        {
            if (errors != null)
                foreach (ValidationError error in errors)
                    Errors.Add(error);
        }

        public static readonly ValidationResult Success = new ValidationResult();

        public bool Equals(ValidationResult other)
        {
            if (other == null)
                return false;
            return other.IsValid == IsValid;
        }

        public override bool Equals(object obj)
        {
            //return base.Equals(obj);
            return Equals(obj as ValidationResult);
        }

        public override int GetHashCode()
        {
            //return base.GetHashCode();
            return Errors.GetHashCode();
        }
    }
}
